﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace NextDart
{
    public class NextDartConfiguration : ConfigurationSection
    {
        public static NextDartConfiguration Instance { get; set; }

        static NextDartConfiguration()
        {
            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var section = (NextDartConfiguration)config.GetSection("nextDartConfiguration");
            Instance = section;
        }

        [ConfigurationProperty("link", IsRequired = true)]
        public string Link
        {
            get { return this["link"] as string; }
            set { this["link"] = value; }
        }

        public string Station
        {
            get 
            {
                int pos = Link.ToLower().IndexOf("station=");
                if (pos == -1) return "";
                return Link.Substring(pos + 8);
            }
        }

        [ConfigurationProperty("discardInterval")]
        public int DiscardInterval
        {
            get { return Convert.ToInt32(this["discardInterval"]); }
            set { this["discardInterval"] = value; }
        }

        [ConfigurationProperty("northBound")]
        public bool NorthBound
        {
            get { return Convert.ToBoolean(this["northBound"]); }
            set { this["northBound"] = value; }
        }
    }
}
